from fastapi import APIRouter, Query
from services.corpus import query_all_corpus, add_corpus, delete_corpus_by_id, update_corpus_by_id
from models.request_model import CreateCorpusRequest, UpdateCorpusRequest

router = APIRouter()

@router.get("/corpus")
async def get_all_corpus(
    question: str = Query(None, description="问题"),
    answer: str = Query(None, description="答案"),
    status: bool = Query(None, description="是否启用"),
    from_model: str = Query(None, description="来源"),
    from_class: str = Query(None, description="类型")
):
    return await query_all_corpus(question, answer, status, from_model, from_class)

@router.post("/corpus")
async def create_corpus(body: CreateCorpusRequest):
    return await add_corpus(
        body.question,
        body.answer,
        body.status,
        body.from_model,
        body.from_class
    )

@router.delete("/corpus/{corpus_id}")
async def delete_corpus(corpus_id: int):
    return await delete_corpus_by_id(corpus_id)

@router.put("/corpus")
async def update_corpus(body: UpdateCorpusRequest):
    return await update_corpus_by_id(
        body.id,
        body.question,
        body.answer,
        body.status,
        body.from_model,
        body.from_class
    )